#!/bin/bash
# $Id$

set -eETa
set -o pipefail
. ./files/env
. ./files/buildscripts.fn
trap '_chk_err' 1 2 3 15 ERR # not very usefull, but
export -f _chk_err

make_cd ()
{
	./bin/clean-all
	./bin/mk-dir-struct.sh
	./bin/fetch-src
	non_slackware_build # if build host is not slackware

	./bin/build-auxbuildroot 
	./bin/build-nemopkg 
	./bin/build-installcd 	
	./bin/build-initram 
	./bin/build-kernel 

	./bin/cp-pkgs-to-cdtree
	# docs, tools ...
	./bin/cp-cdtree-files
	./bin/make-iso
}

make_dsktool ()
{
	./bin/mk-dir-struct.sh
	./bin/fetch-src
	non_slackware_build # if build host is not slackware
	./bin/build-auxbuildroot 
	chroot $auxbuildroot_dir ./BIN/build-nemopkg encdb
	chroot $auxbuildroot_dir ./BIN/build-nemopkg rngtools
	./bin/build-dsktool
}

# help
if [ ! "$1" -o "$1" = "-h" -o "$1" = "-help" ]; then
	echo "
	
	Build options:

		netinstall: makes a netinstall CD.

		cdinstall: makes an Slackware CD.

		dsktool: make dsktool util.
"
	exit 1
fi

# root
if [ "$UID" != "0" ]; then
	echo "

	Must run as root!!
	
	I need to create the auxroot build env and then chroot to
	it, i will try not to harm your current environment.


"
	exit 1
fi

# main
case "$1" in
	'netinstall')
		time make_cd 2>&1 | tee ./tmp/build.log
		;;
	'cdinstall')
		./tools/cp-slackware-sets.sh 2>&1 | tee ./tmp/build.log
		time make_cd 2>&1 | tee -a ./tmp/build.log
		;;
	'dsktool')
		make_dsktool 2>&1 | tee ./tmp/build.log
		;;
	*)
		$@		
		;;
esac
		
echo -e "\n MAKECD $1: DONE\n "
set +eET
